package com.zmn.plat.admin.controller.extension.serv.category.group;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zmn.common.utils.response.ResponseUtil;
import com.zmn.plat.admin.controller.PlatBaseController;
import com.zmn.plat.business.interfaces.extension.serv.category.ExtensionServCategoryGroupBService;
import com.zmn.plat.model.entity.extension.serv.category.group.ExtensionServCategoryGroupQuery;
import com.zmn.plat.model.vo.extension.serv.category.group.ExtensionServCategoryGroupVO;
import com.zmn.plat.services.interfaces.category.BaseCategoryService;
import com.zmn.plat.services.interfaces.extension.category.ExtensionCategoryService;
import com.zmn.plat.services.interfaces.extension.serv.category.ExtensionServCategoryAssociationService;
import com.zmn.plat.services.interfaces.extension.serv.category.ExtensionServCategoryService;
import com.zmn.plat.services.interfaces.extension.serv.category.group.ExtensionServCategoryGroupService;
import com.zmn.plat.services.interfaces.servcategory.ServAssCategoryService;

/**
 * 服务推广分类-推广分类关联
 *
 * @author linfeng
 * @since 2019-12-24 10:55:48
 */
public class ExtensionServCategoryGroupBaseController extends PlatBaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    protected ExtensionServCategoryGroupService extensionServCategoryGroupService;
    @Resource
    protected ExtensionServCategoryGroupBService extensionServCategoryGroupBService;
    @Resource
    protected ExtensionCategoryService extensionCategoryService;
    @Resource
    protected ExtensionServCategoryService extensionServCategoryService;
    @Resource
    protected ExtensionServCategoryAssociationService extensionServCategoryAssociationService;
    @Resource
    BaseCategoryService baseCategoryService;
    @Resource
    ServAssCategoryService servAssCategoryService;

    /**
     * 描述：分类联动（推广服务分类查询关联的推广分类）
     * 
     * @param extensionServCategId
     *            推广服务分类ID
     */
    void loadListChilds(HttpServletResponse response, Integer extensionServCategId) {

        if (extensionServCategId <= 0) {
            ResponseUtil.outWrite(response, "[]");
            return;
        }

        List<ExtensionServCategoryGroupVO> extensionServCategoryGroupVOS = new ArrayList<>();
        ExtensionServCategoryGroupQuery extensionServCategoryGroupQuery = new ExtensionServCategoryGroupQuery();
        extensionServCategoryGroupQuery.setExtensionServCategId(extensionServCategId);
        extensionServCategoryGroupVOS = extensionServCategoryGroupService.listByQuery(extensionServCategoryGroupQuery);
        StringBuilder sb = new StringBuilder("[");
        String jsonFormat = "[\"%s\",\"%s\"]%s ";

        for (int i = 0; i < extensionServCategoryGroupVOS.size(); i++) {
            ExtensionServCategoryGroupVO item = extensionServCategoryGroupVOS.get(i);
            sb.append(String.format(jsonFormat, item.getCategId(), item.getExtensionCategName(),
                (i == extensionServCategoryGroupVOS.size() - 1 ? "" : ",")));
        }
        sb.append("]");

        ResponseUtil.outWrite(response, sb.toString());
    }
}
